using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Lzfy_His_Service.Models
{
    /// <summary>
    /// 银行基础信息
    /// </summary>
    [Table("BankInfo")]
    public class BankInfo
    {
        /// <summary>
        /// 银行ID
        /// </summary>
        [Key]
        public int Id { get; set; }

        /// <summary>
        /// 标准银行名称
        /// </summary>
        [Required]
        [StringLength(100)]
        public string StandardName { get; set; } = string.Empty;

        /// <summary>
        /// 银行简称
        /// </summary>
        [StringLength(50)]
        public string? ShortName { get; set; }

        /// <summary>
        /// 英文名称
        /// </summary>
        [StringLength(100)]
        public string? EnglishName { get; set; }

        /// <summary>
        /// 银行代码
        /// </summary>
        [StringLength(20)]
        public string? BankCode { get; set; }

        /// <summary>
        /// 卡号长度规则
        /// </summary>
        [StringLength(50)]
        public string? CardLengthRule { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsActive { get; set; } = true;

        /// <summary>
        /// 是否为自定义银行
        /// </summary>
        public bool IsCustom { get; set; } = false;

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; } = DateTime.Now;

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdatedAt { get; set; } = DateTime.Now;

        /// <summary>
        /// 创建人
        /// </summary>
        [StringLength(50)]
        public string? CreatedBy { get; set; }

        /// <summary>
        /// 更新人
        /// </summary>
        [StringLength(50)]
        public string? UpdatedBy { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [StringLength(500)]
        public string? Remark { get; set; }

        /// <summary>
        /// 支持的卡类型
        /// </summary>
        [StringLength(100)]
        public string? SupportedCardTypes { get; set; } = "debit,credit";

        /// <summary>
        /// 描述信息
        /// </summary>
        [StringLength(1000)]
        public string? Description { get; set; }

        /// <summary>
        /// BIN码映射列表
        /// </summary>
        public virtual ICollection<BankBinMapping> BinMappings { get; set; } = new List<BankBinMapping>();

        /// <summary>
        /// 银行别名列表
        /// </summary>
        public virtual ICollection<BankNameAlias> NameAliases { get; set; } = new List<BankNameAlias>();
    }

    /// <summary>
    /// 银行BIN码映射
    /// </summary>
    [Table("BankBinMapping")]
    public class BankBinMapping
    {
        /// <summary>
        /// 映射ID
        /// </summary>
        [Key]
        public int Id { get; set; }

        /// <summary>
        /// 银行ID
        /// </summary>
        [Required]
        public int BankId { get; set; }

        /// <summary>
        /// BIN码
        /// </summary>
        [Required]
        [StringLength(10)]
        public string BinCode { get; set; } = string.Empty;

        /// <summary>
        /// 卡片类型
        /// </summary>
        [StringLength(50)]
        public string? CardType { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsActive { get; set; } = true;

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; } = DateTime.Now;

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdatedAt { get; set; } = DateTime.Now;

        /// <summary>
        /// 创建人
        /// </summary>
        [StringLength(50)]
        public string? CreatedBy { get; set; }

        /// <summary>
        /// 更新人
        /// </summary>
        [StringLength(50)]
        public string? UpdatedBy { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [StringLength(500)]
        public string? Remark { get; set; }

        /// <summary>
        /// 关联的银行信息
        /// </summary>
        [ForeignKey("BankId")]
        public virtual BankInfo Bank { get; set; } = null!;
    }

    /// <summary>
    /// 银行名称别名
    /// </summary>
    [Table("BankNameAlias")]
    public class BankNameAlias
    {
        /// <summary>
        /// 别名ID
        /// </summary>
        [Key]
        public int Id { get; set; }

        /// <summary>
        /// 银行ID
        /// </summary>
        [Required]
        public int BankId { get; set; }

        /// <summary>
        /// 别名
        /// </summary>
        [Required]
        [StringLength(100)]
        public string AliasName { get; set; } = string.Empty;

        /// <summary>
        /// 别名类型
        /// </summary>
        [Required]
        [StringLength(20)]
        public string AliasType { get; set; } = "COMMON";

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsActive { get; set; } = true;

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; } = DateTime.Now;

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdatedAt { get; set; } = DateTime.Now;

        /// <summary>
        /// 创建人
        /// </summary>
        [StringLength(50)]
        public string? CreatedBy { get; set; }

        /// <summary>
        /// 更新人
        /// </summary>
        [StringLength(50)]
        public string? UpdatedBy { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [StringLength(500)]
        public string? Remark { get; set; }

        /// <summary>
        /// 关联的银行信息
        /// </summary>
        [ForeignKey("BankId")]
        public virtual BankInfo Bank { get; set; } = null!;
    }

    /// <summary>
    /// 银行信息变更日志
    /// </summary>
    [Table("BankInfoChangeLog")]
    public class BankInfoChangeLog
    {
        /// <summary>
        /// 日志ID
        /// </summary>
        [Key]
        public int Id { get; set; }

        /// <summary>
        /// 银行ID
        /// </summary>
        [Required]
        public int BankId { get; set; }

        /// <summary>
        /// 变更类型
        /// </summary>
        [Required]
        [StringLength(20)]
        public string ChangeType { get; set; } = string.Empty;

        /// <summary>
        /// 表名
        /// </summary>
        [Required]
        [StringLength(50)]
        public string TableName { get; set; } = string.Empty;

        /// <summary>
        /// 字段名
        /// </summary>
        [StringLength(50)]
        public string? FieldName { get; set; }

        /// <summary>
        /// 原值
        /// </summary>
        public string? OldValue { get; set; }

        /// <summary>
        /// 新值
        /// </summary>
        public string? NewValue { get; set; }

        /// <summary>
        /// 变更原因
        /// </summary>
        [StringLength(500)]
        public string? ChangeReason { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; } = DateTime.Now;

        /// <summary>
        /// 创建人
        /// </summary>
        [StringLength(50)]
        public string? CreatedBy { get; set; }

        /// <summary>
        /// 关联的银行信息
        /// </summary>
        [ForeignKey("BankId")]
        public virtual BankInfo Bank { get; set; } = null!;
    }
}